//
//  MyDoubleLabelView.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/10/18.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "MyDoubleLabelView.h"
#import "JTCSM.h"

@interface MyDoubleLabelView (){
    
    CGFloat height;
    CGFloat width;
}

@end

@implementation MyDoubleLabelView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithFrame:(CGRect)frame titleFontsize:(CGFloat)titlefont titlecolor:(UIColor *)titlecolor contentFontsize:(CGFloat)contentfont contentcolor:(UIColor *)contentcolor{
    self = [super initWithFrame:frame];
    if (self) {
        
        height = frame.size.height;
        width = frame.size.width;
        
        self.titleLabel = [UILabel initWithFrame:CGRectZero text:@"123" font:titlefont textAlignment:NSTextAlignmentCenter texcolor:titlecolor backgroundColor:nil];
        [self addSubview:self.titleLabel];
        
        self.contentLabel = [UILabel initWithFrame:CGRectZero text:@"123" font:contentfont textAlignment:NSTextAlignmentCenter texcolor:contentcolor backgroundColor:nil];
        [self addSubview:self.contentLabel];
        
    }
    
    return self;
}
- (id)initWithFrame:(CGRect)frame leftTitleFontsize:(CGFloat)titlefont titlecolor:(UIColor *)titlecolor contentFontsize:(CGFloat)contentfont contentcolor:(UIColor *)contentcolor{
    self = [super initWithFrame:frame];
    if (self) {
        
        height = frame.size.height;
        width = frame.size.width;
        
        self.titleLabel = [UILabel initWithFrame:CGRectZero text:@"123" font:titlefont textAlignment:NSTextAlignmentLeft texcolor:titlecolor backgroundColor:nil];
        [self addSubview:self.titleLabel];
        
        self.contentLabel = [UILabel initWithFrame:CGRectZero text:@"123" font:contentfont textAlignment:NSTextAlignmentLeft texcolor:contentcolor backgroundColor:nil];
        [self addSubview:self.contentLabel];
        
    }
    
    return self;
}

- (void)setvalueWithModel:(id)model{
    self.titleLabel.text = [model objectForKey:KDoubleLabelTitle];
    self.contentLabel.text = [NSString stringWithFormat:@"%@",[model objectForKey:KDoubleLabelContent]];
    CGRect rect = [df labelHeightWithContent:self.titleLabel.text width:width font:self.titleLabel.font.pointSize];
    
    CGRect rect1 = [df labelHeightWithContent:self.contentLabel.text width:width font:self.contentLabel.font.pointSize];
    
    CGFloat changeLabelY = 0;
    
    
    self.titleLabel.frame = CGRectMake(0, changeLabelY, width, rect.size.height);
    self.contentLabel.frame = CGRectMake(0, changeLabelY+rect.size.height, width, rect1.size.height);
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, KVIEW_Y(self.contentLabel));
}

- (void)newsetvalueWithModel:(id)model{
    self.titleLabel.text = [model objectForKey:KDoubleLabelTitle];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.contentLabel.text = [NSString stringWithFormat:@"%@",[model objectForKey:KDoubleLabelContent]];
    self.contentLabel.textAlignment = NSTextAlignmentCenter;
    CGRect rect = [df labelHeightWithContent:self.titleLabel.text width:width font:self.titleLabel.font.pointSize];
    
    CGRect rect1 = [df labelHeightWithContent:self.contentLabel.text width:width font:self.contentLabel.font.pointSize];
    
    CGFloat changeLabelY = 0;
    
    
    self.titleLabel.frame = CGRectMake(0, changeLabelY, width, rect.size.height);
    self.contentLabel.frame = CGRectMake(0, changeLabelY+rect.size.height, width, rect1.size.height);
    self.frame = CGRectMake(self.frame.origin.x, (height-rect1.size.height-rect.size.height)/2, self.frame.size.width, KVIEW_Y(self.contentLabel));
}

- (void)InsertSpacesetvalueWithModel:(id)model changeLabelY:(CGFloat)Y{
    self.titleLabel.text = [model objectForKey:KDoubleLabelTitle];
    self.contentLabel.text = [NSString stringWithFormat:@"%@",[model objectForKey:KDoubleLabelContent]];
    CGRect rect = [df labelHeightWithContent:self.titleLabel.text width:width font:self.titleLabel.font.pointSize];
    
    CGRect rect1 = [df labelHeightWithContent:self.contentLabel.text width:width font:self.contentLabel.font.pointSize];
    
    CGFloat changeLabelY = Y;
    
    
    self.titleLabel.frame = CGRectMake(0, (height-rect1.size.height-rect.size.height-changeLabelY)/2, width, rect.size.height);
    self.contentLabel.frame = CGRectMake(0, changeLabelY+KVIEW_Y(self.titleLabel), width, rect1.size.height);
}


@end
